/**
 * RealTimeInfoView
 * @author helio
 */
var RealTimeInfoView = Ext.extend(BasicPanel,{
	
	initlize : function() {
		
		if(!this.detailsGrid) {
			
			this.detailsStore = new Ext.data.GroupingStore({
			    proxy: new Ext.data.MemoryProxy(this.detailsJson),
			    reader: new Ext.data.JsonReader({
					root: 'details',
		            fields: ['code','content', 'date', 'status', 'comment','detail','type']
				}),				
				sortInfo:{field: 'status', direction: "ASC"},
            	groupField: 'type'
			});
			
			var expander = new Ext.ux.grid.RowExpander({
		        tpl : new Ext.Template(
		            '<p style="color:red;">{comment}</p><div>{detail}</div>'
		        )
		    });

			
			this.detailsGrid = new Ext.grid.GridPanel({
				
				title: '及时信息显示平台',
				stripeRows: true,
				border: false,
				autoExpandColumn: 'pname',
								
				viewConfig: {
			        forceFit: true,
					enableRowBody:true,
		            showPreview:true
			    },
		
				store: this.detailsStore,
				
				columns: [expander, {
	           		header: "编号",
	           		dataIndex: 'code',
	           		width: 60,
					sortable: false
	       		},{
	           		header: "内容",
	           		dataIndex: 'content',
	           		align: 'left',
					sortable: false
	        	},{
	           		header: "日期",
	           		dataIndex: 'date',
	           		width: 70,
	           		align: 'right',
					renderer: Ext.util.Format.dateRenderer('Y-m-d'),
					sortable: false
	        	},{
	           		header: "状态",
	           		dataIndex: 'status',
	           		width: 70,
	           		align: 'center',
	           		renderer: function(val,p,r) {return '<span style="color:red;">' + val + '</span>';},
					sortable: false
	        	},{
	           		header: "类型",
	           		dataIndex: 'type'
	        	}],
				
        		plugins: expander,

				view: new Ext.grid.GroupingView({
					forceFit: true,
					showGroupName: false,
					hideGroupedColumn: true
		        }),

				listeners: {
					'activate': function() {
						alert("show");
					},
					'hide': function() {
						alert("hide");	
					}
				}
			
			});
			
			this.detailsStore.load();
		}
		
		
	},
	
	getCorePanel : function() {
		if (!this.detailsGrid) {
			this.initlize();
		}
		return this.detailsGrid;
	},
	
	initDetailsJson: function() {
		
		this.getRealtimeInfo();
				
		SALE.Action.interval = setInterval(this.getRealtimeInfo.createDelegate(this),300000);
	},
	
	getRealtimeInfo : function() {
		SALE.Action.getRealtimeInfo(this.refreshDetailsJson.createDelegate(this));
	},
	
	refreshDetailsJson : function(details) {
		this.detailsJson.details = [];
		this.detailsJson.details = details;
		if(this.detailsStore) {
			this.detailsStore.reload();
		}
	}
});
